package com.yuhq.helloworld.repositories;

import com.yuhq.helloworld.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

//@RepositoryDefinition(domainClass = User.class,idClass = Integer.class)
public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecificationExecutor<User> {


    public List<User> findByAgeGreaterThan(Integer age);


    //根据用户名查询
    public User findByUserName(String userName);

    //根据用户名前模糊查询并且年龄小于指定值
    public List<User> findByUserNameStartingWithAndAgeLessThan(String userName, Integer age);

    //根据用户名后模糊查询并且年龄小于指定值
    public List<User> findByUserNameEndingWithAndAgeLessThan(String userName, Integer age);

    public List<User> findByUserNameIsInOrAgeGreaterThan(List<String> userNames, Integer age);


    @Modifying
    @Query("UPDATE  User SET userName=?2 WHERE id=?1")
    public int modifyUser(Integer id, String userName);


}
